/**
  @file drv_io.h

  @date 2010-02-26

  @version v5.1

  The file implement driver IOCTL defines and macros
*/

#ifndef _DRV_IO_H_
#define _DRV_IO_H_

#include "usw/include/drv_enum.h"
#include "usw/include/drv_common.h"
#include "drv_api.h"


/**********************************************************************************
              Define Typedef, define and Data Structure
***********************************************************************************/

#define HASH_KEY_LENGTH_MODE_SINGLE      0
#define HASH_KEY_LENGTH_MODE_DOUBLE      1
#define HASH_KEY_LENGTH_MODE_QUAD        2

#define _DRV_FIB_ACC_M_1

/* Tcam/Hash/Tbl/Reg I/O operation mutex control */
#ifndef PACKET_TX_USE_SPINLOCK
#define DRV_ENTRY_LOCK(lchip)         sal_mutex_lock(p_drv_master[lchip]->p_entry_mutex)
#define DRV_ENTRY_UNLOCK(lchip)       sal_mutex_unlock(p_drv_master[lchip]->p_entry_mutex)
#define DRV_SUP1_ENTRY_LOCK(lchip)         sal_mutex_lock(p_drv_master[lchip]->p_entry_mutex)
#define DRV_SUP1_ENTRY_UNLOCK(lchip)       sal_mutex_unlock(p_drv_master[lchip]->p_entry_mutex)
#else
#define DRV_ENTRY_LOCK(lchip)          sal_spinlock_lock((sal_spinlock_t*)p_drv_master[lchip]->p_entry_mutex)
#define DRV_ENTRY_UNLOCK(lchip)       sal_spinlock_unlock((sal_spinlock_t*)p_drv_master[lchip]->p_entry_mutex)
#define DRV_SUP1_ENTRY_LOCK(lchip)          sal_spinlock_lock((sal_spinlock_t*)p_drv_master[lchip]->p_entry_mutex)
#define DRV_SUP1_ENTRY_UNLOCK(lchip)       sal_spinlock_unlock((sal_spinlock_t*)p_drv_master[lchip]->p_entry_mutex)
#endif
#define DRV_TCAM_LOCK(lchip)          sal_mutex_lock(p_drv_master[lchip]->p_tcam_write_mutex)
#define DRV_TCAM_UNLOCK(lchip)        sal_mutex_unlock(p_drv_master[lchip]->p_tcam_write_mutex)

struct addr_array_s
{
    uint8 valid;
    uint32 start_addr;
    uint32 end_addr;
};
typedef struct addr_array_s addr_array_t;

/**********************************************************************************
                      Define API function interfaces
***********************************************************************************/
/**
 @brief remove tcam entry interface according to key id and index
*/
extern int32
drv_usw_chip_sram_tbl_null(uint8 lchip, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);
extern int32
drv_usw_chip_sram_tbl_read2(uint8 lchip, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);
extern int32
drv_usw_chip_sram_tbl_write2(uint8 lchip, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);
extern int32
drv_usw_chip_sram_tbl_write3(uint8 lchip, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);
extern int32
drv_usw_chip_dyn_tbl_read2(uint8 lchip, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);
extern int32
drv_usw_chip_dyn_tbl_write2(uint8 lchip,uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);
extern int32
drv_usw_chip_dyn_tbl_lpm(uint8 lchip, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);
extern int32
drv_usw_chip_lpm_tbl_write(uint8 lchip, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);
extern int32
drv_usw_chip_dyn_tbl_read(uint8 lchip, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);
extern int32
drv_usw_chip_dyn_tbl_write(uint8 lchip, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);
extern int32
drv_usw_chip_sram_tbl_read(uint8 lchip, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);

extern int32
drv_usw_chip_sram_tbl_write(uint8 lchip, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);

extern int32
drv_usw_chip_tcam_tbl_read(uint8 lchip_offset, uint32 index, uint32 cmd, uint8 oper_bmp, uint32 *entry);

extern int32
drv_usw_chip_tcam_tbl_write(uint8 lchip_offset, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* entry);

extern int32
drv_usw_chip_tcam_tbl_remove(uint8 lchip_offset, uint32 index, uint32 cmd, uint8 oper_bmp, uint32*);
extern int32
drv_tmm_chip_sram_tbl_read(uint8 lchip, uint32 tbl_id, uint32 index, uint32* data);
extern int32
drv_tmm_chip_sram_tbl_write(uint8 lchip, uint32 tbl_id, uint32 index, uint32* data);

extern int32
drv_usw_chip_write_tcam_entry(uint8 chip_id, uint8 tcam_type, uint32 blknum, uint32 index, uint32* data, uint32* mask, uint8* ds);

extern int32
drv_usw_chip_remove_tcam_entry(uint8 chip_id, uint8 tcam_type, uint32 blknum, uint32 tcam_index, uint8* ds);

extern int32
drv_usw_chip_convert_tcam_dump_content(uint8 lchip, uint32 tcam_entry_width, uint32 *data, uint32 *mask, uint8* p_empty);

extern int32
drv_chip_pci_intf_adjust_en(uint8 lchip, uint8 enable);
extern int32
drv_chip_common_init(uint8 lchip);
extern int32
drv_usw_chip_dyn_tbl_mask_write2(uint8 lchip, uint32 index, uint32 cmd, uint8 oper_bmp, uint32* data);

#endif /*end of _DRV_IO_H*/

